package com.fyzk.activity.user;

import android.content.Context;
import android.content.Intent;
import android.util.AttributeSet;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.FrameLayout;

import com.fyzk.activity.user.xiangxi.ZhuihaoDetailActivity;
import com.fyzk.adapter.UserListAdapter;
import com.fyzk.bean.BetRecordResponse;
import com.fyzk.interfaces.MoreInterface;
import com.fyzk.interfaces.ReTryInterface;
import com.fyzk.interfaces.UpdateInterface;
import com.tyjc.lottery.R;
import com.fyzk.utils.IntentParamUtils;
import com.fyzk.utils.L;
import com.fyzk.view.MsgListView;

import java.util.List;


/**
 * 普通订单记录列表View
 * 
 * 
 */
public class CommonBetRecordView extends FrameLayout implements OnItemClickListener {
	
	private String TAG = this.getClass().getSimpleName();

	NetProgressView netProgressView;
	MsgListView listViewExt;
	UserListAdapter listAdapter;
	public List<BetRecordResponse.OrdersBean> infos;
	private Context context;
	

	public CommonBetRecordView(Context context, AttributeSet attrs,
			int defStyle) {
		super(context, attrs, defStyle);
		this.context = context;
		init();
		// TODO Auto-generated constructor stub
	}

	public CommonBetRecordView(Context context, AttributeSet attrs) {
		this(context, attrs, 0);
		// TODO Auto-generated constructor stub
	}

	public CommonBetRecordView(Context context) {
		this(context, null);
		// TODO Auto-generated constructor stub
	}

	private void init() {
		View.inflate(context, R.layout.layout_recordlist, this);
		netProgressView = (NetProgressView) findViewById(R.id.recordProgressView);
		listViewExt = (MsgListView) findViewById(R.id.recordlist);
//		infos = new ArrayList<BetRecordResponse.OrdersBean>();
		listAdapter = new UserListAdapter(context, infos);
		listViewExt.setAdapter(listAdapter);
		listViewExt.setOnItemClickListener(this);
	}

	/**
	 * 初始化记录列表
	 * 
	 * @param infos
	 */
	public void initRecordList(List<BetRecordResponse.OrdersBean> infos) {
		if (infos != null && infos.size() > 0) {
			L.v(TAG, "initRecordList>>>>>>");
			netProgressView.setVisibility(View.GONE);
			this.infos = infos;

			if (infos.size() < 20) {
				listViewExt.listMore.setClickable(false);
				listViewExt.listMore.setTextStr("无更多数据");
			}else{
				listViewExt.listMore.endNet();
			}
			listAdapter.setInfors(this.infos);
		}
	}

	/**
	 * 为记录列表增加
	 * 
	 * @param infos
	 */
	public void addRecordInfos(List<BetRecordResponse.OrdersBean> infos) {
		netProgressView.setVisibility(View.GONE);
		if (null != this.infos) {
			this.infos.addAll(infos);

			if (this.infos.size() < 20) {
				listViewExt.listMore.setClickable(false);
				listViewExt.listMore.setTextStr("无更多数据");
			}else{
				listViewExt.listMore.endNet();
			}
			listAdapter.setInfors(this.infos);
		}

	}
	public void updateFinish() {
		listViewExt.onRefreshComplete();
	}

	/**
	 * 刷新列表
	 * 
	 * @param infos
	 */
	public void refrashInfos(List<BetRecordResponse.OrdersBean> infos) {

		if(null!=this.infos){
			netProgressView.setVisibility(View.GONE);
			this.infos.clear();
			this.infos.addAll(infos);
			listAdapter.setInfors(this.infos);
		}
	}

	public void setMoreInterface(MoreInterface moreInterface) {
		listViewExt.setMoreInterface(moreInterface);
	}

	public void setUpdateInterface(UpdateInterface updateInterface) {
		listViewExt.setUpdateInterface(updateInterface);
	}
	
	public void showData() {
		netProgressView.setVisibility(View.VISIBLE);
		netProgressView.dismiss();

	}

	public void showLoading() {
		netProgressView.setVisibility(View.VISIBLE);
		netProgressView.waiting();
	}

	public void showNoneRecord(String msg) {
		netProgressView.setVisibility(View.VISIBLE);
		netProgressView.noneRecord(msg);
	}
	
	public void showFail(String msg){
		if (this.infos != null) {
			infos.clear();
			listAdapter.setInfors(this.infos);
		}
		listViewExt.listMore.setClickable(false);
		netProgressView.setVisibility(View.VISIBLE);
		netProgressView.fail(msg);
	}
	
	public void setRetryInterface(ReTryInterface reTry){
		netProgressView.setRetryInterface(reTry);
	}

	@Override
	public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
		// TODO Auto-generated method stub
		Intent intent = new Intent(this.context , ZhuihaoDetailActivity.class);
		intent.putExtra(IntentParamUtils.BETDETAILID, this.infos.get(position-1).getOrderid());
		this.context.startActivity(intent);
	}

	


	

}
